package com.shao.channelHandler.handler;

import com.shao.SrpcBootstrap;
import com.shao.transport.message.SrpcResponse;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CompletableFuture;

/**
 * 这是用来测试的处理器
 * @author PaoFu
 * @version 1.0
 * @data 2025/4/17 14:08
 */
@Slf4j
public class MySimpleChannelInboundHandler extends SimpleChannelInboundHandler<SrpcResponse> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, SrpcResponse srpcResponse) throws Exception {
        // 来自服务提供方的消息
        Object result = srpcResponse.getBody();
        // 从全局挂起的请求中找到与之匹配的 completableFuture
        CompletableFuture<Object> completableFuture = SrpcBootstrap.PENDING_REQUEST.get(srpcResponse.getRequestId());
        completableFuture.complete(result);
    }
}
